#include "core.h"

int ae_startup()
{
#if defined(AE_WIN32)
	WSADATA wsaData;
	WSAStartup(MAKEWORD(2, 2), &wsaData);
#endif
	return 0;
}

int ae_cleanup()
{
#if defined(AE_WIN32)
	WSACleanup();
#endif
	return 0;
}

ae_time_t ae_timestamp(ae_time_t* retval)
{
	ae_time_t current;
#if defined(AE_WIN32)
	FILETIME ft;
	ULARGE_INTEGER ui;

	GetSystemTimeAsFileTime(&ft);
	ui.LowPart = ft.dwLowDateTime;
	ui.HighPart =  ft.dwHighDateTime;
	current = (ae_time_t) ((ui.QuadPart - 116444736000000000) / 10000);
#else
	struct timeval tv;
	struct timezone tz;

	gettimeofday(&tv, &tz);
	current = (ae_time_t) tv.tv_sec * 1000 + tv.tv_usec / 1000;
#endif
	if(retval)
		*retval = current;
	return current;
}
